package com.qf.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * 环绕增强类
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
public class MyAroundAdvice implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {


        Object result = null;
        try {
            System.out.println("前置");
            //执行原始方法: 如果不调用，原始方法不执行
            result = invocation.proceed();
            System.out.println("后置增强");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("异常增强");
        } finally {
            System.out.println("无论有没有异常都会执行");
        }
        return result;
    }
}
